# -*- coding: utf-8 -*-
"""
@Time    : 2022/9/16 09:07
@Author  : huanghuang
"""
from pyhtml2pdf import converter
from common.g.g import G_SETTINGS
from common.pkg.str_id import get_short_uuid


def generate_pdf(source: str, target: str = None) -> str:
    """
        根据html或者url生成pdf 并返回pdf路径
    :param source: html源文件内容或者url路径
    :param target: 保存文件的地址
    :return: str
    """
    if target is None:
        target = f"{G_SETTINGS.static_root}/{get_short_uuid()}.pdf"
    converter.convert(source=source, target=target, install_driver=True)
    return target
